import request from '@/utils/request'

// 获取所有组合
export function getAllPortfolios() {
  return request({
    url: '/api/portfolios',
    method: 'get'
  })
}

// 根据ID获取组合
export function getPortfolioById(id) {
  return request({
    url: `/api/portfolios/${id}`,
    method: 'get'
  })
}

// 搜索组合
export function searchPortfolios(keyword) {
  return request({
    url: '/api/portfolios/search',
    method: 'get',
    params: { keyword }
  })
}

// 根据策略ID获取组合
export function getPortfoliosByStrategyId(strategyId) {
  return request({
    url: `/api/portfolios/strategy/${strategyId}`,
    method: 'get'
  })
}

// 根据基金ID获取组合
export function getPortfoliosByFundId(fundId) {
  return request({
    url: `/api/portfolios/fund/${fundId}`,
    method: 'get'
  })
}

// 创建组合
export function createPortfolio(data) {
  return request({
    url: '/api/portfolios',
    method: 'post',
    data
  })
}

// 更新组合
export function updatePortfolio(id, data) {
  return request({
    url: `/api/portfolios/${id}`,
    method: 'put',
    data
  })
}

// 删除组合
export function deletePortfolio(id) {
  return request({
    url: `/api/portfolios/${id}`,
    method: 'delete'
  })
}

// 更新组合的基金配置
export function updatePortfolioFunds(portfolioId, fundWeights) {
  return request({
    url: `/api/portfolios/${portfolioId}/funds`,
    method: 'put',
    data: fundWeights
  })
}

// 向组合添加基金
export function addFundToPortfolio(portfolioId, fundId, weight) {
  return request({
    url: `/api/portfolios/${portfolioId}/funds/${fundId}`,
    method: 'post',
    params: { weight }
  })
}

// 从组合移除基金
export function removeFundFromPortfolio(portfolioId, fundId) {
  return request({
    url: `/api/portfolios/${portfolioId}/funds/${fundId}`,
    method: 'delete'
  })
}

// 更新组合中基金的权重
export function updateFundWeight(portfolioId, fundId, weight) {
  return request({
    url: `/api/portfolios/${portfolioId}/funds/${fundId}/weight`,
    method: 'put',
    params: { weight }
  })
} 